package com.springboot.original.service;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.springboot.original.common.utils.ApplicationContextUtil;
import com.springboot.original.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.util.concurrent.ListenableFuture;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Auther: ZhangYongMing
 * @Date: 2018/11/21 15:21
 * @Description:
 */
public class DynamicAddJob implements SimpleJob {

    @Override
    public void execute(ShardingContext shardingContext){
        String jobName = shardingContext.getJobName();//获取Job名称
        String jobParam = shardingContext.getJobParameter();
        System.out.println("======= " + jobName + "----" + jobParam);
        String shardParamter = shardingContext.getShardingParameter();
        System.out.println("分片参数：" + shardParamter);
        String time = new SimpleDateFormat("HH:mm:ss").format(new Date());
        System.out.println(time + ":开始执行简单任务");

//        KafkaTemplate kafkaTemplate = ApplicationContextUtil.getBean(KafkaTemplate.class);
//        UserService userService = ApplicationContextUtil.getBean(UserService.class);
//
//        String p = userService.getFromRedis("aaa");
//        System.out.println(p);
//
//        ListenableFuture future = kafkaTemplate.send("test1", "这是从定时任务来的数据");
//
//        future.addCallback(o -> System.out.println("send-消息发送成功!"), throwable -> System.out.println("消息发送失败"));

    }

}